{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-10-30T06:51:05.337866Z",
     "start_time": "2024-10-30T06:51:05.261149Z"
    }
   },
   "source": [
    "# coding:utf-8\n",
    "\n",
    "class Father(object):\n",
    "    __money = 2000      # 私房钱\n",
    "    property = 50000    # 总资产\n",
    "\n",
    "    def __init__(self, job, salary):\n",
    "        self.job = job          # 工作\n",
    "        self.salary = salary    # 月薪\n",
    "        print(\"我是老慕, 工作是{}, 月薪{}元\".format(self.job, self.salary))\n",
    "\n",
    "    def __private_money(self):\n",
    "        print(\"我存了{}元私房钱, 哈哈哈...\".format(self.__money))\n",
    "        print(\"嘘! 不要告诉别人!\")\n",
    "\n",
    "    def working(self):\n",
    "        print(\"好好学习, 努力工作\")\n",
    "\n",
    "\n",
    "class Son(Father):\n",
    "    def __init__(self, job, salary):\n",
    "        super().__init__(job, salary)\n",
    "        print(\"我是小慕, 我没有私房钱, 好想哭...\")\n",
    "\n",
    "\n",
    "xiaomu = Son(\"xx\", 111)\n",
    "xiaomu.working()\n",
    "print(\"看看老慕的总资产, 哇! {}元!\".format(Father.property))\n",
    "# print(\"老慕, 我能看看你有多少私房钱吗? {}元?\".format(Father.__money))\n",
    "# xiaomu.__private_money()\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我是小慕, 我没有私房钱, 好想哭...\n",
      "好好学习, 努力工作\n",
      "看看老慕的总资产, 哇! 50000元!\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "type object 'Father' has no attribute '__money'",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mAttributeError\u001B[0m                            Traceback (most recent call last)",
      "Cell \u001B[0;32mIn[1], line 28\u001B[0m\n\u001B[1;32m     26\u001B[0m xiaomu\u001B[38;5;241m.\u001B[39mworking()\n\u001B[1;32m     27\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m看看老慕的总资产, 哇! \u001B[39m\u001B[38;5;132;01m{}\u001B[39;00m\u001B[38;5;124m元!\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;241m.\u001B[39mformat(Father\u001B[38;5;241m.\u001B[39mproperty))\n\u001B[0;32m---> 28\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m老慕, 我能看看你有多少私房钱吗? \u001B[39m\u001B[38;5;132;01m{}\u001B[39;00m\u001B[38;5;124m元?\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;241m.\u001B[39mformat(\u001B[43mFather\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m__money\u001B[49m))\n\u001B[1;32m     29\u001B[0m xiaomu\u001B[38;5;241m.\u001B[39m__private_money()\n",
      "\u001B[0;31mAttributeError\u001B[0m: type object 'Father' has no attribute '__money'"
     ]
    }
   ],
   "execution_count": 1
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
